<?php
/**
 * Created by PhpStorm.
 * User: wumengmeng <wu_mengmeng@foxmail.com>
 * Date: 2019/4/26 0026
 * Time: 14:35
 */

namespace HiCommon\Service;

use HiCommon\MongodbModel\MongoLaravelLog;
use HiCommon\Repository\OrderPayRefundRepository;
use Yansongda\Pay\Pay;

class PayYanSongDaService extends BaseService
{

    //    static protected $wx_config = [
    //      'appid' => 'wx20566816a0372a67', // APP APPID
    //      'app_id' => 'wxe32410ce2999a155', // 公众号 APPID
    //      'miniapp_id' => 'wx4848cf1b4f659a5c', // 小程序 APPID
    //      'mch_id' => '1553306381',//商户号
    //      'key' => '1553306381m1553306381m1553306381',//api 支付key
    //      'notify_url' => 'http://test-jcapi.7deer.cn/api-wxpay_notify',//回调地址
    //      //      'notify_url' => 'http://test-jcmini.7deer.cn/small_wechat_pay_mini_notify',//回调地址 - 测试小程序
    //      //      'notify_url' => 'https://xdminiapi.chxing.cn/small_wechat_pay_mini_notify',//回调地址 - 正式小程序
    //      'cert_client' => LARAVEL_APP_DIR.'cert/wechat_pay/apiclient_cert.pem', // optional，退款等情况时用到
    //      'cert_key' => LARAVEL_APP_DIR.'cert/wechat_pay/apiclient_key.pem',// optional，退款等情况时用到
    //      'log' => [ // optional
    //                 'file' => LARAVEL_STORAGE.'/log/yansongda_pay/wechat/wechat.log',
    //                 'level' => 'info', // 建议生产环境等级调整为 info，开发环境为 debug
    //                 'type' => 'daily', // optional, 可选 daily.
    //                 'max_file' => 180, // optional, 当 type 为 daily 时有效，默认 30 天
    //      ],
    //      'http' => [ // optional
    //                  'timeout' => 5.0,
    //                  'connect_timeout' => 5.0,
    //                  // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
    //      ],
    //      //      'mode' => 'dev', // optional, dev/hk;当为 `hk` 时，为香港 gateway。
    //    ];
    //
    //    static protected $ali_config = [
    //      'app_id' => '2021001101693550',
    //      'notify_url' => 'http://test-jcapi.7deer.cn/api-alipay_notify',
    //      'return_url' => 'http://yansongda.cn/return.php',
    //      'ali_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmJiBwr3KOWTUIPwog5WtWGtZreScARv0oIJ9jKt54+G5YWWV/OGyrja8m5FO5Ns49Xlbji6v1RWkYW9rhl1IdxnkKDqpFnmnKdG3ob5nntvBc1xwyIXF3EQApJsP1fFMmASKmMjoRJ8mZlXZzcdUEljq3olk7qU2u0byDf2UbEMcdUk/ApfBLsz1aPRLbrPnMbLqr2fcnowsvc96iqD71x4FxFlBnBB7ObCp5T6MGmjEYA/Y51tCEFspjhdfm4k3HOILPWltVk7GStHbvi125L64ob8Q8nGQHQcBvH89ZKnyIBxILhyHsUiG0Q32P19vvNsVCH4pqMM+ntc8VnjnzQIDAQAB',
    //      // 加密方式： **RSA2**
    //      'private_key' => 'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCVvaNHWTQXgV0xPsRkAT0iUc0TADWX1qrOcOkgYYit/PgLNP9qxBGcGDGTiaqx2ClbJ2uAGf+D4AkMDyQbkgGbFtZrTY9Iw/pkJorXvQM/IvVxjoEOAvuj+MdWSK8vdwBx5pUz9geg1X8nnMYj0oCZNBLYO6wsFuRZmyN/a42AOA8vGAxseQllbusXFPoR2FgnuvyBiUVM9q7w2B8lyrQqhmplmoOLSeeL4bAzfSEUIQjwQGMwGleOwTtunE06IIr6mfQFIP2Lj40LI9Nz0MUrS0Sqxno9vRRoNmJo4nbiQnSzvB8IUVFHu9sDyJED35pRIC7TIXJhy6b0i5XKGsrlAgMBAAECggEAIXvxih/hbSwpabyub+pzADyojgoq8dQ4B8fp6arFxJpf4Smtv/MuOOiUFXjgabp7rP2IpXGq2JN9kmvEWEHzB/o4YnBKjSv9zu1reMi0dCbeGdGS/E4gdU9JS/se6Y9D0zSLwr3OgOGc+H+vMw18YkXpvN7DJmzMDVmKu5CSaMxHElWShuDTPmNEI5e5Yy5mCtA6J2xcbZ4su6Y8hzcPTCyYHbhbWU7DFCHblPx2IChMNWgojUO/tsnUVtH7kKDzD74cnYrazHPesFfldr954PdWfLIryT4maxJ4szzZv1sJxB4iklbIu4geplegKWUY4br2cs4PPaoWUALzEHTTFQKBgQDu8kVSQT3djUBAz55wjNm8afBrXk2UmzmiSKWD8unNGVaZ1kqmPSIP/LNmAoVE2cR5uDaYBOCwHgyMNLXNnv4cvqDlne4hlBP3/R+itqbRknIz3r+yciKbzBnx79W8cHToxMD1/1CNDc+qPBh4MQjtsck07czv7bygYjoLEBbPgwKBgQCgbYOQC2o6p2tBBEyc/5v6RuD/OtdsiGXJ1+MWOJkQPHU/JaMZsxYa1QVQV8hGNzW4gIIm42PFVjtLRyLGe3SJpcstibVFzXoYTxN6iCXwuXmlI21USWmHzbA+adM48ogXCDCVju1ki8y+gsmcC9DsH4sZTuIOOSHFC7O/htFHdwKBgANAkOj5slndnk5DhSiLAjuqRXdwpSWspzAqRPZyy/PasG8Pl5yDoH8PNXHh/uZdAGuXskaHand7MTiHTyIpU9QYVCBL8f3LAiqR62hPjB22HI/QLFPFcesk8AV2+jXCYhT4+JdgjjwdQAJVJxAbur9heBecVPm/Bp44OAoGggj5AoGARwBRAtZafH0ONec+NRnXoYvvFmanYwx26D8Y7QO9knb/eSQiLESbWuK+iFFhfNoAd5jAgY+P342LjoR8OpX2/NiYtJ3G0Y7gI5QTzd4l1IVx9glY4L3g68632tehOQn1+yOPxRFNtXs98W8W5W5BV8+aE2hbGeplLL1CH1j+lH8CgYB0UJYgT0mn6+ZjBaBE0km27nDCM3NKeS1kzLV2/2I6Td8olT/aLSFTtWxkJWYY7oaWkZ0lwmj84xLe1KXHNYD0nnZew4XDmhaB3qHQN/pZayatVHZ6pHiG5obk22jcvEV+TuzAMm2dpE/Cd9ADuHMtqswkCo3/WnrRN1jVgkiJ5A==',
    //      'log' => [ // optional
    //                 'file' => LARAVEL_STORAGE.'/log/yansongda_pay/ali/ali.log',
    //                 'level' => 'info', // 建议生产环境等级调整为 info，开发环境为 debug
    //                 'type' => 'daily', // optional, 可选 daily.
    //                 'max_file' => 180, // optional, 当 type 为 daily 时有效，默认 30 天
    //      ],
    //      'http' => [ // optional
    //                  'timeout' => 5.0,
    //                  'connect_timeout' => 5.0,
    //                  // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
    //      ],
    //      //      'mode' => 'dev', // optional,设置此参数，将进入沙箱模式
    //    ];

    public function wx_config()
    {
        $wx_config = [
          'appid'       => env('WX_APPID_APP', ''), // APP APPID
          'app_id'      => env('WX_APPID_WECHAT', ''), // 公众号 APPID
          'miniapp_id'  => env('WX_APPID_MINI', ''), // 小程序 APPID
          'mch_id'      => env('WX_MCH_ID', ''),//商户号
          'key'         => env('WX_API_KEY', ''),//api 支付key
          'notify_url'  => env('WX_PAY_NOTIFY_URL', ''),//回调地址
          //      'notify_url' => 'http://test-jcmini.7deer.cn/small_wechat_pay_mini_notify',//回调地址 - 测试小程序
          //      'notify_url' => 'https://xdminiapi.chxing.cn/small_wechat_pay_mini_notify',//回调地址 - 正式小程序
          'cert_client' => LARAVEL_APP_DIR . 'cert/wechat_pay/apiclient_cert.pem', // optional，退款等情况时用到
          'cert_key'    => LARAVEL_APP_DIR . 'cert/wechat_pay/apiclient_key.pem',// optional，退款等情况时用到
          'log'         => [ // optional
                             'file'     => LARAVEL_STORAGE . '/log/yansongda_pay/wechat/wechat.log',
                             'level'    => 'info', // 建议生产环境等级调整为 info，开发环境为 debug
                             'type'     => 'daily', // optional, 可选 daily.
                             'max_file' => 180, // optional, 当 type 为 daily 时有效，默认 30 天
          ],
          'http'        => [ // optional
                             'timeout'         => 5.0,
                             'connect_timeout' => 5.0,
                             // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
          ],
          //      'mode' => 'dev', // optional, dev/hk;当为 `hk` 时，为香港 gateway。
        ];
        return $wx_config;
    }

    public function ali_config()
    {
        $ali_config = [
          'app_id'         => env('ALI_APPID', ''),
          'notify_url'     => env('ALI_PAY_NOTIFY_URL', ''),
          'return_url'     => env('ALI_PAY_RETURN_URL', ''),
          'ali_public_key' => env('ALI_ALI_PUBLIC_KEY', ''),
          // 加密方式： **RSA2**
          'private_key'    => env('ALI_PRIVATE_KEY', ''),
          'log'            => [ // optional
                                'file'     => LARAVEL_STORAGE . '/log/yansongda_pay/ali/ali.log',
                                'level'    => 'info', // 建议生产环境等级调整为 info，开发环境为 debug
                                'type'     => 'daily', // optional, 可选 daily.
                                'max_file' => 180, // optional, 当 type 为 daily 时有效，默认 30 天
          ],
          'http'           => [ // optional
                                'timeout'         => 5.0,
                                'connect_timeout' => 5.0,
                                // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
          ],
          //      'mode' => 'dev', // optional,设置此参数，将进入沙箱模式
        ];
        return $ali_config;

    }

    public function pay_wechat()
    {
        return Pay::wechat(self::wx_config());
    }

    public function pay_ali()
    {
        return Pay::alipay(self::ali_config());
    }

    public function make_mongodb_log($arr_data)
    {
        MongoLaravelLog::create($arr_data);
    }

}